package com.shop.cereshop.agent.service.product.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.cereshop.agent.dao.product.AgentProductClassifyDAO;
import com.shop.cereshop.agent.page.product.AgentProductClassifyVO;
import com.shop.cereshop.agent.service.product.AgentProductClassifyService;
import com.shop.cereshop.commons.domain.agentProduct.CereAgentProductClassify;
import com.shop.cereshop.commons.utils.EmptyUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lx
 * @date 2025/11/3 13:36
 * @version 1.0
 */

@Service
public class AgentProductClassifyServiceImpl extends ServiceImpl<AgentProductClassifyDAO, CereAgentProductClassify> implements AgentProductClassifyService {
    @Override
    public List<AgentProductClassifyVO> getClassifyList(Long classifyId) {
        List<AgentProductClassifyVO> classifyList;
        List<CereAgentProductClassify> list;
        if (EmptyUtils.isEmpty(classifyId)) {
            //不传参数：查询一级分类
            list = lambdaQuery().eq(CereAgentProductClassify::getClassifyPid, 0)
                    .eq(CereAgentProductClassify::getClassifyLevel, 1)
                    .orderByAsc(CereAgentProductClassify::getSort)
                    .list();
            classifyList = BeanUtil.copyToList(list, AgentProductClassifyVO.class);
        } else {
            //传二级分类id：查询该分类下的所有子分类
            list = lambdaQuery().eq(CereAgentProductClassify::getClassifyPid, classifyId)
                    .orderByAsc(CereAgentProductClassify::getSort)
                    .list();
            classifyList = BeanUtil.copyToList(list, AgentProductClassifyVO.class);
        }
        return classifyList;
    }
}
